const app = getApp()
Page({
  data: {
    colors: ['#5ecedb', '#5ecedb', '#5ecedb', '#5ecedb', '#5ecedb', '#5ecedb']
  },
  start: function(e) {
    var array = this.data.colors
    var index = e.currentTarget.dataset.index
    array[index] = '#21B3CF'
    this.setData({
      colors: array
    })
  },
  end: function(e) {
    var array = this.data.colors
    var index = e.currentTarget.dataset.index
    array[index] = '#5ecedb'
    this.setData({
      colors: array
    })
    if (index == 0) {
      wx.cloud.database({
        env: 'gtss-2b1812'
      }).collection('News').where({
        dept: app.globalData.userDept
      }).count().then(res => {
        if (res.total > 0) {
          wx.navigateTo({
            url: '../teaNews/teaNews'
          })
        } else {
          wx.showToast({
            title: '管理员未发布任何新闻',
            icon: 'none',
            duration: 2000
          })
        }
      })
    } else if (index == 1) {
      wx.cloud.database({
        env: 'gtss-2b1812'
      }).collection('Notice').where({
        dept: app.globalData.userDept
      }).count().then(res => {
        if (res.total > 0) {
          wx.navigateTo({
            url: '../notice/notice'
          })
        } else {
          wx.showToast({
            title: '管理员未发布任何公告',
            icon: 'none',
            duration: 2000
          })
        }
      })
    } else if (index == 2) {
      wx.cloud.database({
        env: 'gtss-2b1812'
      }).collection('Message').where({
        receiveId: app.globalData.userId
      }).count().then(res => {
        if (res.total > 0) {
          wx.navigateTo({
            url: '../message/message'
          })
        } else {
          wx.showToast({
            title: '您还没收到任何消息',
            icon: 'none',
            duration: 2000
          })
        }
      })
    } else if (index == 3) {
      wx.navigateTo({
        url: '../changePas/changePas'
      })
    } else if (index == 4) {
      wx.cloud.database({
        env: 'gtss-2b1812'
      }).collection('Topic').where({
        teaId: app.globalData.userId
      }).count().then(res => {
        if (res.total > 0) {
          wx.navigateTo({
            url: '../stuDskt/stuDskt?from=teaSy'
          })
        } else {
          wx.showToast({
            title: '您还未发布任何课题',
            icon: 'none',
            duration: 2000
          })
        }
      })
    } else if (index == 5) {
      wx.cloud.database({
        env: 'gtss-2b1812'
      }).collection('Teacher').doc(app.globalData.userId).field({
        teaState: true
      }).get().then(res => {
        if (res.data.teaState == 0) {
          wx.navigateTo({
            url: '../teaFb/teaFb'
          })
        } else if (res.data.teaState == 1) {
          wx.showToast({
            title: '您已带满规定学生数量，无需再发布课题！',
            icon: 'none',
            duration: 2000
          })
        }
      })
    }
  }
})